//
//  lxCategoryCell.m
//  luodansc
//
//  Created by 倫 星 on 2012/10/04.
//  Copyright (c) 2012年 方正株式会社. All rights reserved.
//

#import "lxCategoryCell.h"
#import "lxCategoryInfoEntity.h"
#import "lxLabel.h"
#import "lxImageView.h"
#import <QuartzCore/QuartzCore.h>

@implementation lxCategoryCell

@synthesize image_goods_tubmb = _image_goods_tubmb;
@synthesize lb_category_name = _lb_category_name;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.frame = frame;
        
        self.backgroundColor = [UIColor clearColor];
        
        float cell_width = self.bounds.size.width;
        float cell_height = self.bounds.size.height;
        
        int middle = 5;
        
        float height = (cell_height - middle * 2) / 4;
        
        float img_width = (cell_width - middle * 2);
        float img_height = height * 3;
        
        CGRect ret_image_goods_tubmb = CGRectMake(middle, middle, img_width, img_height);
        _image_goods_tubmb = [[lxImageView alloc] initWithFrame:ret_image_goods_tubmb];
        //圆角
        [_image_goods_tubmb.layer setMasksToBounds:YES];
        [_image_goods_tubmb.layer setCornerRadius:15];
        [_image_goods_tubmb setUserInteractionEnabled:NO];
        
        CGRect ret_lb_category_name = CGRectMake(cell_width / 4, img_height + middle, cell_width / 2, height);
        _lb_category_name = [[lxLabel alloc] initWithFrame:ret_lb_category_name];
        _lb_category_name.adjustsFontSizeToFitWidth = YES;
        _lb_category_name.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:_image_goods_tubmb];
        [self addSubview:_lb_category_name];
    }
    return self;
}

- (BOOL)refreshData:(lxbaseEntity *)entity {
    BOOL result = [super refreshData:entity];
    if (NO == result) {
        return result;
    }
    
    lxCategoryInfoEntity *lxentity = (lxCategoryInfoEntity*)entity;
    NSString *goods_thumb = lxentity.goodsEntity.goods_img;
    
    if (nil != goods_thumb) {
        NSString *str_url = [NSString stringWithFormat:@"%@%@", web_root, goods_thumb];
        [_image_goods_tubmb loadImageFromURL:str_url];
    }
    
    _lb_category_name.text = lxentity.name;
    return YES;
}

- (void)dealloc {
    [_image_goods_tubmb release];
    [_lb_category_name release];
    
    [super dealloc];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
